
#include "iostream"
#include "vector"
#include "unordered_map"
#include "unordered_set"
#include "algorithm"
#include "string"
#include "list"
#include "string.h"


class OneLoop{
public:
    std::vector<int> times;
    std::vector<int> queues;

    int& min_in_queues(){
        int min=0;
        for(int i=1;i<queues.size();i++){
            if(queues[i]<queues[min]){
                min=i;
            }
        }
        return queues[min];
    }
    void run(
            int a,int b
            ){
        int sum=0;
        for(int i=0;i<a;i++){
            int t;std::cin>>t;
            times.push_back(t);
            sum+=t;
        }
        queues.resize(b);
        std::sort(times.begin(),times.end());
        for(int i= 0;i<times.size();i++){
            int& min=min_in_queues();
            sum+=min;//等待时间
            min+=times[i];
        }
        std::sort(queues.begin(),queues.end());
        printf("%d\n",sum);
    }
};
class Solution {
public:
    void run() {

        bool first = true;
        int a,b,c,d,e;
//        std::string s1,s2;
        while (
                std::cin>>a>>b
//                std::getline(std::cin,s1)
                )
        {
//            std::getline(std::cin,s2);
            OneLoop loop;
            loop.run(a,b);
        }
    }
};

int main() {
//    bool cur_num= true;
    Solution().run();
    return 0;
}

